package top.mccat.filesystem.utils;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;

/**
 * @author JMY
 */
@Data
public class AjaxResult {
    private int responseCode;
    private String message;
    private Object objectResult;

    private boolean result;

    private AjaxResult(int responseCode, String message){
        this.responseCode = responseCode;
        this.message = message;
    }

    private AjaxResult(int responseCode, String message, Object o){
        this.responseCode = responseCode;
        this.message = message;
        this.objectResult = o;
    }

    public AjaxResult(int responseCode, String message, Object objectResult, boolean result) {
        this.responseCode = responseCode;
        this.message = message;
        this.objectResult = objectResult;
        this.result = result;
    }

    /**
     * 发送不带对象的正确结果
     * @param message
     * @return
     */
    public static AjaxResult successResult(String message) {
        return new AjaxResult(EssentialsConstant.SUCCESS_CODE,message);
    }

    /**
     * 发送带对象的正确结果
     * @param message
     * @param o
     * @return
     */
    public static AjaxResult successResult(String message, Object o) {
        return new AjaxResult(EssentialsConstant.SUCCESS_CODE,message,o);
    }

    /**
     * 发送带对象和boolean的正确结果
     * @param message
     * @param o
     * @return
     */
    public static AjaxResult successResult(String message, Object o, boolean result) {
        return new AjaxResult(EssentialsConstant.SUCCESS_CODE,message,o, result);
    }

    /**
     * 发送不带对象的服务器错误结果
     * @param message
     * @return
     */
    public static AjaxResult errorResult(String message) {
        return new AjaxResult(EssentialsConstant.SERVER_ERROR_CODE,message);
    }

    /**
     * 发送带对象的服务器错误结果
     * @param message
     * @param o
     * @return
     */
    public static AjaxResult errorResult(String message, Object o) {
        return new AjaxResult(EssentialsConstant.SERVER_ERROR_CODE,message,o);
    }
}
